import Addition from "@/components/Addition";
import QueryMaterial2 from "@/components/QueryMaterial2";
import QueryVendor from "@/components/QueryVendor";
import { s_getcommontableinfo, s_operate2data, s_operateInfo, s_updateInfo, state2text, status2text } from "@/services/basis";
import { ActionType, EditableFormInstance, EditableProTable, ProCard, ProColumns, ProForm, ProFormDatePicker, ProFormDateRangePicker, ProFormInstance, ProFormRadio, ProFormSelect, ProFormText, ProTable } from "@ant-design/pro-components";
import { Button, Col, message, Modal, Row, Space, Tag } from "antd";
import moment from "moment";
import { Item } from "rc-menu";
import { getSelection } from "@/services/selections";
import React, { useEffect, useRef, useState } from "react";
import QueryUserDefine from "@/components/QueryUserDefine";

const App:React.FC=()=>{
     const [selectedRecord,setSelectedRecord]=useState<DataType[]>([]);
     const [open,setOpen]=useState(false);
     const [open2,setOpen2]=useState(false);
     const [open_vendor,setOpenVendor]=useState(false);
     const [etype,setEtype]=useState(1);
     const [saveType,setSaveType]=useState(1);//保存类型：1保存，2保存并下达
     const [selectVendor,setSelectVendor]=useState<DataType3[]>([]);//表体中选择匹配供应商
     const [vendorKeys,setVendorKeys]=useState<any[]>([]);//在行明细中，已选择的供应商ID
     
     const [dataSource,setDataSource]=useState< readonly DataType2[]>([]);
     const [tableDetail,setTableDetail]=useState<DataType[]>([]);
     const [priceType,setPriceType]=useState(1);

     const [queryMaterial,setQueryMaterial]=useState([]);
     const [queryVendor,setQueryVendor]=useState([]);
     const [queryVendor2,setQueryVendor2]=useState<DataType3[]>([]);
     const [queryVendor2_id,setQueryVendor2_id]=useState('0');
     const [queryUserDefine,setQueryUserDefine]=useState([]);
     const [rowno,setRowno]=useState(0);//选择自由项的行号
     const [addition,setAddition]=useState([]);

     const mtable_ref=useRef<ActionType>();
     const mtable2_ref=useRef<ActionType>();
     const mform_ref=useRef<ProFormInstance>();
     const table_ref_vendor=useRef<ActionType>();
     const editableRef=useRef<EditableFormInstance<DataType2>>();
     const editorFormRef = useRef<EditableFormInstance<DataType2>>();

    //   主界面表
      interface DataType{
        id:number,code:string,operate_time:string,dep_name:string,operater_name:string,business_name:string,
        operater_id:number,business_id:number,source_xid:number,to_xid:number,org_id:number,pricetype:number,
        state:number,status:number,to_name:string,addition:string,valid_begindate:string,valid_enddate:string,
        hadquote:number,
      }

      const columns:ProColumns<DataType>[]=[
        {dataIndex:'id',title:'ID'},{dataIndex:'code',title:'单据编号'},{dataIndex:'dep_name',title:'部门'},
        {dataIndex:'operater_name',title:'询价人'},{dataIndex:'business_name',title:'业务员'},
        {dataIndex:'to_name',title:'供应商'},{dataIndex:'addition',hidden:true}, 
        {dataIndex:'operater_id',hidden:true},{dataIndex:'business_id',hidden:true},
        {dataIndex:'to_xid',hidden:true},{dataIndex:'source_xid',hidden:true},{dataIndex:'org_id',hidden:true},
        {dataIndex:'querytype',title:'报价类型',
         render:(text)=>text==1?'整单报价':'明细报价',
        },
        {dataIndex:'operate_time',title:'申请日期',
            render:(text:any)=>moment(moment(text).toDate()).format('YYYY-MM-DD'),
         },
         {dataIndex:'valid_begindate',title:'生效日期',
            render:(text:any)=>moment(moment(text).toDate()).format('YYYY-MM-DD'),
         },
         {dataIndex:'valid_enddate',title:'失效日期',
            render:(text:any)=>moment(moment(text).toDate()).format('YYYY-MM-DD'),
         },
         {dataIndex:'state',title:'进度',
            render:(text:any)=>state2text(2,text)},
         {dataIndex:'status',title:'状态',fixed:'right',width:80,
            render:(text:any)=>status2text(text),
         },
         {dataIndex:'hadquote',title:'是否报价',
            render:(text)=>text==1?<Tag>已报价</Tag>:<Tag color='red'>未报价</Tag>,
         } 

      ];
      
      //当组件选择物料时，更新表格并重载
      useEffect(()=>{
         if(queryMaterial.length>0){
         var x:any[]=editorFormRef.current?.getRowsData?.();
         // alert(JSON.stringify(x));
         if(x==undefined)
            x=[];
         queryMaterial.map((item:any)=>{
            x?.push({rid:Math.random().toFixed(10),id:Math.random().toFixed(10).toString(),
                      material_id:item.id,material_code:item.code,material_name:item.name,
                      invstd:item.invstd,invstd2:item.invstd2,munit_name:item.munit_name,  
                      hassample:0,deliverdate:moment().format('YYYY-MM-DD'),quantity:1, dosample:0,
                      userdefine_id:'[]',vendor_id:'[]' 
            });
         });
         // alert(JSON.stringify(x));
         setDataSource(x);
          
         mform_ref.current?.setFieldValue('editortable',x);
          mtable2_ref.current?.reloadAndRest?.();
      }
      },[queryMaterial]);

     //当组件表头更新时，更新表头整单供应商
      useEffect(()=>{
          if(queryVendor.length>0){
            var vendor_id:any[]=[];
            var vendor_name:any[]=[];
            queryVendor.map((item:any)=>{
                vendor_id.push(item.id);
                vendor_name.push(item.sname);
            });
            //更新表单
            mform_ref.current?.setFieldsValue({vendor_id,vendor_name});
            
          }
      },[queryVendor]);

      //当组件返回结果时，更新表格中的自定义字段
      useEffect(()=>{
         //  if(queryUserDefine.length>0){
              var userdefine_id:any[]=[];
              var userdefine_value:any[]=[];
              queryUserDefine.map((item:any)=>{
                userdefine_id.push({uid:item.uid,value:item.value});
               //文本框
               if(item.vlabel==''){
                   userdefine_value.push(''.concat(item.uname,':',item.value));  
               }else if(item.vlabel!=''){
                   userdefine_value.push(''.concat(item.uname,':',item.vlabel));
               };

              });
           
             editorFormRef.current?.setRowData?.(rowno.toString(),
                   {userdefine_id:JSON.stringify(userdefine_id),
                   userdefine_name:userdefine_value.toString()});
         //  }
         },[queryUserDefine]);

      interface DataType2{
         rid:number, 
         id:number,material_id:number,material_code:string,material_name:string,
         invstd:string,invstd2:string,munit_name:string,userdefine_id:string,userdefine_name:string,
         quantity:number,deliverdate:string,memo:string,dosample:number,
         vendor_id:string,vendor_name:string,
         // 以下为报价表新增项
         price:number,taxrate:number,total:number,netprice:number,nettotal:number,isstepprice:number,
         minquantity:number,state2:number,memo2:number,isreject:number,x_id:number,opinion:string,
      }

       
      const columns2:ProColumns<DataType2>[]=[
         {dataIndex:'rid',title:'RID',editable:false,},
         {dataIndex:'id',title:'ID',editable:false,},
         {dataIndex:'material_id',title:'物料ID',editable:false},
         {dataIndex:'material_code',title:'物料编码',editable:false},
         {dataIndex:'material_name',title:'物料名称',editable:false,},
         {dataIndex:'invstd',title:'规格',editable:false,},
         {dataIndex:'invstd2',title:'型号',editable:false,},
         {dataIndex:'userdefine_id',title:'属性ID',editable:false,hidden:true,},
         {dataIndex:'userdefine_name',title:'属性名',editable:false,},
         {title:'属性',editable:false,hidden:true,
            render:(text,record)=><QueryUserDefine setData={setQueryUserDefine} 
                          objtype={1} dotype={1} id={record.material_id} setRowno={setRowno} rowno={record.rid} />
         },
         {dataIndex:'munit_name',title:'主计量单位',editable:false,},
         {dataIndex:'quantity',title:'需求数量',valueType:'digit',editable:false,},
         {dataIndex:'deliverdate',title:'需求日期',valueType:'date',editable:false,},
         {dataIndex:'dosample',title:'是否需打样',valueType:'select',editable:false,
            valueEnum:{1:{text:'是'},0:{text:'否'}}
         },
         {dataIndex:'vendor_id',title:'报价供应商ID',editable:false,hidden:true,},
         {dataIndex:'vendor_name',title:'报价供应商名',editable:false,hidden:true,},
         {dataIndex:'memo',title:'备注',editable:false,},
         // 以下为报价表项
         {dataIndex:'taxrate',title:'税率%',valueType:'digit',
            fieldProps:(_,{rowIndex})=>{
               return {
                  onChange:()=>{
                     // alert(rowIndex);
                     const rowdata=editorFormRef?.current?.getRowData?.(rowIndex);
                     // alert(JSON.stringify(rowdata));
                     const quantity=rowdata?.quantity==null?0:rowdata?.quantity;
                     const price=rowdata?.price==null?0:rowdata?.price;
                     const taxrate=rowdata?.taxrate==null?0:rowdata?.taxrate;
                     editorFormRef.current?.setRowData?.(rowIndex,
                        {total:quantity*price,
                          netprice:price/(1+taxrate/100),
                          nettotal:(price/(1+taxrate/100))*quantity,
                        });
                  },
               }
            }
         },
         {dataIndex:'price',title:'含税单价',valueType:'digit',
            fieldProps:(_,{rowIndex})=>{
               return {
                  onChange:()=>{
                  const rowdata=editorFormRef.current?.getRowData?.(rowIndex);
                  const quantity=rowdata?.quantity==null?0:rowdata?.quantity;
                  const price=rowdata?.price==null?0:rowdata?.price;
                  const taxrate=rowdata?.taxrate==null?0:rowdata?.taxrate;
                  editorFormRef.current?.setRowData?.(rowIndex,{
                     total:quantity*price,
                     netprice:price/(1+taxrate/100),
                     nettotal:(price/(1+taxrate/100))*quantity,
                  });
               },
              }
            }
         },
         {dataIndex:'total',title:'价税合计',valueType:'digit',editable:false},
         {dataIndex:'minquantity',title:'最少采购量',valueType:'digit',},
          {dataIndex:'isstepprice',title:'是否阶梯价',valueType:'select',
            valueEnum:{
               0:{text:'否'},
               1:{text:'是'},
            },
          },
         {dataIndex:'isreject',title:'是否拒绝',valueType:'select',
            valueEnum:{
               0:{text:'否'},
               1:{text:'是'},
            }
         },
         {dataIndex:'memo2',title:'报价说明'},
         {dataIndex:'netprice',title:'不含税单价',valueType:'digit',editable:false,},
         {dataIndex:'nettotal',title:'不含税金额',valueType:'digit',editable:false,},
         {
            title:'操作',
            fixed:'right',
            valueType:'option',
            hidden:true,
            render:(text,record,_,action)=>[
               <a key='edit2'
                  onClick={()=>{
                      alert(record.rid);
                     action?.startEditable?.(record.rid);}}
               >
                   编辑
               </a>,
               <a  key='del2'
                   onClick={()=>{
                     var x:any[]=editorFormRef.current?.getRowsData?.();
                     //  alert(JSON.stringify(x));
                     setDataSource(x.filter((item)=>item.id!=record.id));
                     // alert(JSON.stringify(x.filter((item)=>item.id!=record.id)));
                     // mtable2_ref.current?.reloadAndRest?.();
                     mform_ref.current?.setFieldValue('editortable',x.filter((item)=>item.rid!=record.rid));
                   }}
               >
                   删除
               </a>,
            ]
         }
      ];

      // var tdata2:DataType2[]=[
      //    {rid:12.23334,id:1,material_id:1,material_code:'6022220998',material_name:'FD专用纸箱',invstd:'55*65*80',invstd2:'',
      //       userdefine_id:'1',userdefine_name:'订单号：X265277',munit_name:'PCS',quantity:500,deliverdate:'2025-03-12',
      //       dosample:0,memo:'准时交货，违约追责',vendor_id:'',vendor_name:'',
      //    },
      //    {rid:2.35562,id:2,material_id:2,material_code:'80995260',material_name:'PVC超大粒子',invstd:'20um',invstd2:'新虹专供',
      //       userdefine_id:'1',userdefine_name:'订单号：X265277',munit_name:'吨',quantity:2,deliverdate:'2025-05-12',
      //       dosample:1,memo:'准时交货，违约追责',vendor_id:'',vendor_name:'',
      //    },
      // ];

   //   tdata3=[...tdata2];

   //   选择匹配的供应商---type:1按物料匹配供应商，2按供应商匹配物料
   async function getAllocatedVendor(type:number,id:number,keys:any,record_id:number){
      const x=await s_getcommontableinfo({x_id:1,source:'v_material2vendor',id,fdata:{type}});
      //  alert(JSON.stringify(x.data[0]));
      if(x.success){
             setSelectVendor(x.data[0]);
             setQueryVendor2_id(record_id.toString());
             //将当前行中已选中--进行标示
             setVendorKeys(keys==null||keys==''?[]:JSON.parse(keys));
             setOpenVendor(true);
         }
      else{
          message.warning('没有匹配的供应商，请先分配');
         setSelectVendor([]);
      };
   }

   //选择供应商--数据类型
   interface DataType3{
      id:number,
      code:string,
      name:string,
      country:string,
      province:string,
      city:string,
      address:string,
      sname:string,
      salecategory2:string,
      material_id:number,
    }
    const columns3:ProColumns<DataType3>[]=[
      {dataIndex:'id',hidden:true},
      {dataIndex:'code',title:'编码'},
      {dataIndex:'name',title:'全称'},
      {dataIndex:'sname',title:'简称'},
      {dataIndex:'country',title:'国家'},
      {dataIndex:'province',title:'省/区'},
      {dataIndex:'city',title:'城市'},
      {dataIndex:'address',title:'详细地址'},
      {dataIndex:'salecategory2',title:'供货类目'},
      {dataIndex:'material_id',hidden:true},
    ];

   //  参数：1确定选择，2取消
    function chooseVendor(type:number){
       if(type==1){
        // 当选择供应商后，更新表格内容
         //  const material_id=queryVendor2[0]?.material_id.toString();
          if(queryVendor2.length>0){
            const vendor_id2=queryVendor2.map((item:any)=>item.id);
            const vendor_name2=queryVendor2.map((item:any)=>item.sname);
            editorFormRef.current?.setRowData?.(queryVendor2_id,
               {vendor_id:JSON.stringify(vendor_id2),vendor_name:vendor_name2.toString()});
         }else{
            editorFormRef.current?.setRowData?.(queryVendor2_id,
               {vendor_id:'[]',vendor_name:''});
         }
            
         setOpenVendor(false);
       }
       else{
         setQueryVendor2([]);
         setOpenVendor(false);
       }
    }
   
    //自动按物料更新表格的供应商
     async function suitVendor(){
      var  x=editorFormRef.current?.getRowsData?.();
      const material_id=x?.map(Item=>Item.material_id);
      //  alert(JSON.stringify(material_id));
      const material2vendor=await s_getcommontableinfo({x_id:1,source:'v_material2vendor',id:0,cate_id:material_id,fdata:{type:3}});
      const mv=material2vendor.data[0];
      //  alert(JSON.stringify(mv));
      x?.map((item:any,index)=>{
         const rid=item.rid;
         const mid=item.material_id;
         const mv2=mv.filter((item2:any)=>item2.material_id==mid);
         var vname='';
         var vid='';
         if(mv2.length>0){
              vname=mv2[0].vendor_name;
              vid=mv2[0].vendor_id;
         }
         editorFormRef.current?.setRowData?.(rid.toString(),{vendor_name:vname,vendor_id:vid,});
        });
     
   }

   // 增加报价单
   function add(){
      setDataSource([]);
      setPriceType(1);
      setEtype(1);
      setOpen(true);
   }
   // 编辑报价单
   async function edit(){
      if(selectedRecord.length==0)
         message.warning('请选择要编辑的行');
      else{
         setEtype(0);
         setPriceType(2);
         // 获取对应的ID明细数据
         const x=await s_getcommontableinfo({x_id:2,source:'v2_quoteprice',id:0,fdata:{mid:selectedRecord[0].id}});
         // alert(JSON.stringify(x.data[0]));
         setDataSource(x.data[0]);
         setOpen(true);
      }
    }
   //  操作报价单/冻结/删除/恢复
   async function operateInfo(n:number){
         // source,x_id,operater_id,otype,id
         if(selectedRecord.length==0)
            message.warning('请选择要操作的行');
         else{
            // [source,px_id,operater_id,etype,otype,pid,JSON.stringify(tdata)]
         // alert(JSON.stringify(selectedRecord[0]));
         const fdata=editorFormRef.current?.getRowsData?.();
         const tdata=fdata?.map((item:any)=>({
                          ...item,
                          deliverdate:moment(moment(item.deliverdate).toDate()).format('YYYY-MM-DD'),
                          savetype:saveType,
         }));
     
       
      // // [source,px_id,operater_id,etype,otype,pid,JSON.stringify(tdata)]
      const x=await s_operate2data({x_id:2,source:'quoteprice',operater_id:1,etype:2,otype:n,
                                    id:selectedRecord.length>0?selectedRecord[0].id:0,
                                    tdata});
         //  const x=await s_operate2data({x_id:2,source:'quoteprice',operater_id:1,etype:2,otype:n,
         //                               id:selectedRecord.length>0?selectedRecord[0].id:0});
          if(x.success){
            message.success('操作成功');
            // mtable_ref.current?.reloadAndRest?.();
            // mform_ref.current?.setFieldValue('editortable',x.data[0]);
            const y=editorFormRef.current?.getRowsData?.();
            y?.map((item:any)=>{
               editorFormRef.current?.setRowData?.(item.rid.toString(),{'isreject':1});
            });
            // mtable2_ref.current?.reloadAndRest?.();

          }else
            message.error('操作错误，请联系管理员。');
         }
      }

    //关闭报价单界面
    function close(){
      
      mtable_ref.current?.reset?.();
      setOpen(false);
      setSelectedRecord([]);
    }

    //保存/下达报价结果
    async function saveAll(type:number){
      // type:1，仅保存；2保存并下达
      //  alert(JSON.stringify(editorFormRef.current?.getRowsData?.()));
      
       mform_ref.current?.submit();
       const x=editorFormRef?.current?.getRowsData?.();
       x?.map((item,index)=>{
         mtable2_ref.current?.saveEditable?.(index);
       });
       
       setSaveType(type);
      //  save();
      //  setOpen(false);
    }
    //保存/下达报价结果--通过主调saveAll传入参数
    async function save(){
      // type:1，仅保存；2保存并下达
      // alert(JSON.stringify(editorFormRef.current?.getRowsData?.()));
      // setOpen(false);
      // alert(JSON.stringify(mform_ref.current?.getFieldsValue()));
      const fdata=editorFormRef.current?.getRowsData?.();
      const tdata=fdata?.map((item:any)=>({
         ...item,
         deliverdate:moment(moment(item.deliverdate).toDate()).format('YYYY-MM-DD'),
         savetype:saveType,
         }));
     
        alert(JSON.stringify(tdata));
      // // [source,px_id,operater_id,etype,otype,pid,JSON.stringify(tdata)]
      const x=await s_operate2data({x_id:2,source:'quoteprice',operater_id:1,etype,otype:0,tdata});
      if(x.success){
         message.success('保存成功');
         mtable_ref.current?.reloadAndRest?.();
         // setOpen(false);
      }else
        message.error('保存失败，请联系管理员');
    }

   //  开始报价，置表格为编辑状态
    function quote(){
      //用一个循环
      const x:any[]=editorFormRef.current?.getRowsData?.();
      x.map((item:any,index)=>{
           mtable2_ref.current?.startEditable?.(index);
         }
      );
    }

      // ==========================================================================================================================
    return <>
           <ProCard title='销售报价'
              extra={<Space>
                       <Button onClick={()=>alert("仅查看，不可编辑")}>查看询价明细</Button>
                       <Button onClick={()=>edit()}>执行报价+</Button>
                       <Button onClick={()=>alert("接收来自于客户的价格")}>接收</Button>
                       <Button onClick={()=>alert("拒绝接收来自于客户的价格")}>拒绝接收</Button>
                    </Space>}
           >
            {JSON.stringify(selectedRecord)}
            
           <ProTable<DataType>  columns={columns} 
            actionRef={mtable_ref}
            rowKey='id'
            request={async ()=>{
               const x=await s_getcommontableinfo({source:'v2_queryprice_main',x_id:2,id:0});
               return {
                  data:x.data[0],
                  success:true,
               }
            }}
            rowSelection={{
               type:'radio',
               onChange(selectedRowKeys, selectedRows, info) {
                  setSelectedRecord(selectedRows);
               },
            }}
            />
            </ProCard  >
            {/* 报价单编辑主界面---------------------------------------------------------------------------------- */}
            <Modal open={open}  width={'90%'} 
                cancelButtonProps={{hidden:true}} okButtonProps={{hidden:true}}
                closable destroyOnClose onClose={()=>setOpen(false)} onCancel={()=>setOpen(false)}
             >
               <ProCard title={etype==1?'新增报价':'编辑报价'}  style={{height:900}}
                 extra={<Space>
                         <Addition source_xid={1} setData={setAddition} type={etype==1?2:1}
                            fdata={{source_table:'addition_queryprice_main',source_code:selectedRecord.length==0?'':selectedRecord[0].code,
                                  source_field:'addition',source_id:selectedRecord.length==0?0:selectedRecord[0].id,
                                  source_value:selectedRecord.length==0||selectedRecord[0].addition==null||selectedRecord[0].addition==''?[]:selectedRecord[0].addition}}
                         />
                         {/* //参数1：source_xid,setData：主调useState函数回传,type:1查看，2编辑，fdata:如下
                         // 参数2：fdata:源表source_table,源source_id,源字段source_field,源单据号/编号source_code,源值source_value */}
                        <Button onClick={()=>operateInfo(14)}>整单拒绝报价</Button>
                        <Button onClick={()=>quote()}>开始报价</Button>
                        <Button onClick={()=>saveAll(1)}>保存报价</Button>
                        <Button onClick={()=>saveAll(2)}>保存并提交报价</Button>
                        <Button onClick={()=>operateInfo(21)}>提交报价</Button>
                        <Button onClick={()=>operateInfo(22)}>撤回报价</Button>
                        <Button onClick={()=>close()}>取消</Button>
                 </Space>}
               >
                  {JSON.stringify(queryMaterial)}
                  {JSON.stringify(queryVendor)}
                  {JSON.stringify(queryVendor2)};
                 自由项: {JSON.stringify(queryUserDefine)}
                 行号： {rowno}
               <ProForm submitter={false} formRef={mform_ref} 
                           initialValues={etype==1?{
                               pricetype:1,querytype:2,operater_id:1,
                               operate_time:moment().format('YYYY-MM-DD'),
                               state:1,status:1,
                           }
                          :{
                              ...selectedRecord[0],
                              editortable:dataSource,
                              validdate:selectedRecord.length>0?[selectedRecord[0].valid_begindate,selectedRecord[0].valid_enddate]:[null,null],
                              priceType:selectedRecord.length>0?selectedRecord[0].pricetype:1,
                           }} 
                           onFinish={()=>save()}
                           >
                  <Row gutter={8}>
                     <Col span={6}>
                           <ProFormText name='id' hidden={true} />
                            
                           <ProFormText name='code' label='报价单号' width={300} 
                                labelCol={{span:12,offset:0}} wrapperCol={{span:12,offset:0}}
                                rules={[{required:true,message:'必须输入'}]}
                                /> 
                           <ProFormSelect name='org_id' label='部门' width={300}
                                request={async ()=>{
                                 var x:any=await getSelection({source:'base_organization',x_id:1});
                                 var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
                                 return x2;
                                }}
                                rules={[{required:true,message:'必须输入'}]}
                           /> 
                           <ProFormSelect name='bussiness_id' label='业务员' width={300}
                               request={async ()=>{
                                   var x:any=await getSelection({ source: 'base_person', x_id: 1 });
                                   var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
                                  return x2;
                            }}
                           /> 
                     </Col>
                     <Col span={6}>
                          <ProFormDatePicker name='operate_time' label='报价日期' width={300}
                               rules={[{required:true,message:'必须输入'}]}/>
                          <ProFormDatePicker name='enddate' label='截止日期' width={300}
                                rules={[{required:true,message:'必须输入'}]}  />
                          <ProFormDateRangePicker name='validdate' label='有效期间' width={300}
                                rules={[{required:true,message:'必须输入'}]}
                           />
                       </Col>
                     <Col span={6}>
                     <ProFormRadio.Group name='querytype' label='报价方式' width={300}
                               options={[{value:1,label:'按整单报价'},{value:2,label:'按明细报价'}]}
                               fieldProps={{
                                 onChange(e) {
                                    alert(JSON.stringify(e.target.value));
                                    setPriceType(e.target.value);
                                 },
                               }}
                             />
                     <ProFormRadio.Group name='pricetype' label='价格类型' width={300}
                               options={[{value:1,label:'批量采购'},{value:2,label:'零星采购'}]}
                            />
                     <ProFormText name='vendor_name' label='报价供应商'  width={300}/> 
                     <ProFormText name='vendor_id' label='报价供应商ID' hidden={true}/> 
                     </Col>
                     <Col span={6}>
                        <ProFormSelect name='state' label='报价进度'  width={300}
                            options={[{value:1,label:'未下达'},{value:2,label:'已下达'},{value:3,label:'供方已确认'},
                              {value:4,label:'供方已拒绝'},{value:5,label:'确认同意'},{value:6,label:'确认不同意'},
                              {value:7,label:'撤销确认'},{value:8,label:'撤销提交'},{value:9,label:'撤回下达'},
                            ]}
                        />
                        <ProFormRadio.Group name='status' label='状态' width={300}
                           options={[{value:0,label:'已制单'},{value:1,label:'进行中'},
                                     {value:2,label:'已冻结'},{value:3,label:'已删除'}
                           ]}
                        />
                        <ProFormSelect name='operater_id' label='操作员' width={300}
                          request={async ()=>{
                           var x:any=await getSelection({ source: 'base_person', x_id: 1 });
                           var x2=x.data.map((item:any)=>({value:item.id,label:item.name}));
                          return x2;
                    }}
                        />
                     </Col>
                  </Row>
                   
                   <EditableProTable<DataType2>
                      rowKey='rid'
                      name='editortable'
                     //  rowSelection={{
                     //    type:'checkbox',
                     //  }}
                      actionRef={mtable2_ref}
                      editableFormRef={editorFormRef}
                     //  value={dataSource}
                      onChange={(data)=>setDataSource(data)}
                      columns={columns2}

                     //  request={async ()=>{
                     //    return {
                     //       data:tdata2,
                     //       success:true,
                     //    }
                     //  }}
                      editable = {{                       // defaultDom = {save,cancel,delete} 可以酌情添加和使用
                        actionRender: (row, config, defaultDom) => [
                          defaultDom.save,
                        //   defaultDom.cancel,
                        ],
                        type:'multiple',
                      }}
                   />
                   </ProForm>
               
               </ProCard>
            </Modal>
            <Modal open={open_vendor} width={'80%'} destroyOnClose closable onCancel={()=>setOpenVendor(false)}
                  onClose={()=>setOpenVendor(false)} okButtonProps={{hidden:true}} cancelButtonProps={{hidden:true}}
                  
               >
               <ProCard title='选择报价供应商' style={{height:600}}
                  extra={<Space>
                     <Button onClick={()=>chooseVendor(1)}>确定</Button>
                     <Button onClick={()=>chooseVendor(2)}>取消</Button>
                  </Space>}
               >
                  <ProForm submitter={false}>
                     {JSON.stringify(vendorKeys)}
                  <ProTable<DataType3>
                    actionRef={table_ref_vendor}
                    dataSource={selectVendor}
                    columns={columns3}
                    rowKey='id'
                    pagination={{
                      pageSize:10,
                      showQuickJumper:true,
                    }}
                  
                    rowSelection={{
                      type:'checkbox',
                      selectedRowKeys:vendorKeys,
                      onChange(selectedRowKeys, selectedRows, info) {
                        // setMaterial({material:selectedRows[0],
                        //              userdefine:userDefines.filter((item:any)=>item.material_id==selectedRows[0].id)});
                        // props.setData({material:selectedRows[0],
                        //   userdefine:userDefines.filter((item:any)=>item.material_id==selectedRows[0].id)});
                           // alert("selectRowKeys:"+JSON.stringify(selectedRowKeys));
                           setQueryVendor2(selectedRows);
                           setVendorKeys(selectedRowKeys);
                        // alert(JSON.stringify(material));
                        // chooseVendor(selectedRows);
                      },
                    }}
                    scroll={{y:300}}
                    search={false}
                    />
                  </ProForm>
               </ProCard>
            </Modal>
          </>
}

export default App;